package com.irdstudio.efp.report.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.limit.service.vo.LmtPrdContVO;
import com.irdstudio.efp.report.service.dao.ZxbsLmtPrdContDao;
import com.irdstudio.efp.report.service.domain.ZxbsLmtPrdCont;
import com.irdstudio.efp.report.service.facade.ZxbsLmtPrdContService;
import com.irdstudio.efp.report.service.vo.ZxbsLmtPrdContVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 授信协议表服务实现
 *
 * @author gcb
 * @date 2020-07-28
 */
@Service("zxbsLmtPrdContService")
public class ZxbsLmtPrdContServiceImpl implements ZxbsLmtPrdContService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(ZxbsLmtPrdContServiceImpl.class);

    @Autowired
    private ZxbsLmtPrdContDao zxbsLmtPrdContDao;

    /**
     * 新增数据
     *
     * @param zxbsLmtPrdContVo
     * @return
     */
    @Override
    public int insert(ZxbsLmtPrdContVO zxbsLmtPrdContVo) {
        logger.debug("当前新增数据为:" + zxbsLmtPrdContVo.toString());
        int num = 0;
        try {
            ZxbsLmtPrdCont zxbsLmtPrdCont = new ZxbsLmtPrdCont();
            beanCopy(zxbsLmtPrdContVo, zxbsLmtPrdCont);
            num = zxbsLmtPrdContDao.insert(zxbsLmtPrdCont);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param zxbsLmtPrdContVo
     * @return
     */
    @Override
    public int deleteByPk(ZxbsLmtPrdContVO zxbsLmtPrdContVo) {
        logger.debug("当前删除数据条件为:" + zxbsLmtPrdContVo);
        int num = 0;
        try {
            ZxbsLmtPrdCont zxbsLmtPrdCont = new ZxbsLmtPrdCont();
            beanCopy(zxbsLmtPrdContVo, zxbsLmtPrdCont);
            num = zxbsLmtPrdContDao.deleteByPk(zxbsLmtPrdCont);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + zxbsLmtPrdContVo + "删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param zxbsLmtPrdContVo
     * @return
     */
    @Override
    public int updateByPk(ZxbsLmtPrdContVO zxbsLmtPrdContVo) {
        logger.debug("当前修改数据为:" + zxbsLmtPrdContVo.toString());
        int num = 0;
        try {
            ZxbsLmtPrdCont zxbsLmtPrdCont = new ZxbsLmtPrdCont();
            beanCopy(zxbsLmtPrdContVo, zxbsLmtPrdCont);
            num = zxbsLmtPrdContDao.updateByPk(zxbsLmtPrdCont);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + zxbsLmtPrdContVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inZxbsLmtPrdContVo
     * @return
     */
    @Override
    public ZxbsLmtPrdContVO queryByPk(ZxbsLmtPrdContVO inZxbsLmtPrdContVo) {
        logger.debug("当前查询参数信息为:" + inZxbsLmtPrdContVo);
        try {
            ZxbsLmtPrdCont queryZxbsLmtPrdCont = new ZxbsLmtPrdCont();
            beanCopy(inZxbsLmtPrdContVo, queryZxbsLmtPrdCont);
            ZxbsLmtPrdCont queryRslZxbsLmtPrdCont = zxbsLmtPrdContDao.queryByPk(queryZxbsLmtPrdCont);
            if (Objects.nonNull(queryRslZxbsLmtPrdCont)) {
                return beanCopy(queryRslZxbsLmtPrdCont, new ZxbsLmtPrdContVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    @Override
    public int insertOrUpdate(List<ZxbsLmtPrdContVO> list) throws Exception {
        return zxbsLmtPrdContDao.insertOrUpdate((List<ZxbsLmtPrdCont>) beansCopy(list, ZxbsLmtPrdCont.class));
    }

    @Override
    public List<ZxbsLmtPrdContVO> queryByLmtApplySeq(ZxbsLmtPrdContVO zxbsLmtPrdContVO) throws Exception {
        return (List<ZxbsLmtPrdContVO>) beansCopy(zxbsLmtPrdContDao.queryByLmtApplySeq(beanCopy(zxbsLmtPrdContVO,new ZxbsLmtPrdCont())), ZxbsLmtPrdContVO.class);
    }
}
